package com.jevons.muffin.crash;



import com.jevons.muffin.BaseApplication;
import com.jevons.muffin.utilcode.CrashPrintUtils;

import java.io.File;

/**
 * uncaughtException处理类,当程序发生Uncaught异常的时候,
 * 由该类来接管程序,并记录发送错误报告.
 * @author linaisheng
 * Created at 2019/1/21.
 */

public class CrashExceptionHandler {

    private static final String TAG = CrashExceptionHandler.class.getSimpleName();

    private static final CrashExceptionHandler INSTANCE = new CrashExceptionHandler();

    private BaseApplication mContext;

    public static CrashExceptionHandler getInstance() {
        return INSTANCE;
    }

    public CrashExceptionHandler init(BaseApplication application) {
        this.mContext = application;

        CustomActivityOnCrash.install(mContext);
        return this;
    }


    public final CrashExceptionHandler initConfig(CrashConfig crashConfig) {
        CustomActivityOnCrash.setConfig(crashConfig);
        return this;
    }


    public final CrashExceptionHandler setLogSwitch(final boolean logSwitch) {
        CrashPrintUtils.getConfig().setLogSwitch(logSwitch);
        return this;
    }

    public final CrashExceptionHandler setConsoleSwitch(final boolean consoleSwitch) {
        CrashPrintUtils.getConfig().setConsoleSwitch(consoleSwitch);
        return this;
    }


    public final CrashExceptionHandler setLog2FileSwitch(final boolean log2FileSwitch) {
        CrashPrintUtils.getConfig().setLog2FileSwitch(log2FileSwitch);
        return this;
    }

    public final CrashExceptionHandler setExceptionDir(final String dir) {
        CrashPrintUtils.getConfig().setExceptionDir(dir);
        return this;
    }

    public final CrashExceptionHandler setExceptionDir(final File dir) {
        CrashPrintUtils.getConfig().setExceptionDir(dir);
        return this;
    }


    public final CrashExceptionHandler setFileExtension(final String fileExtension) {
        CrashPrintUtils.getConfig().setFileExtension(fileExtension);
        return this;
    }

    public final CrashExceptionHandler setExceptionListener(
            CrashPrintUtils.HandleExceptionListener listener) {
        CrashPrintUtils.getConfig().setExceptionListener(listener);
        return this;
    }

}
